﻿namespace HRM.CORE.Machine
{

    using APP.HELPER.Data.Helper;
    using System; using Extra.ERP;
    using System.Data;
    using System.Data.SqlClient;

    public class HRM_TIMEKEEPER_MACHINE
    {
        private DateTime m_Date;
        private string m_EnrollNumber;
        private DateTime m_Hour;
        private Guid m_ID;
        private string m_MachineID;
        private int m_StateInOut;

        public HRM_TIMEKEEPER_MACHINE()
        {
            this.m_ID = Guid.Empty;
            this.m_EnrollNumber = "";
            this.m_Date = DateTime.Now;
            this.m_Hour = DateTime.Now;
            this.m_StateInOut = 0;
            this.m_MachineID = "";
        }

        public HRM_TIMEKEEPER_MACHINE(Guid ID, string EnrollNumber, DateTime Date, DateTime Hour, int StateInOut, string MachineID)
        {
            this.m_ID = ID;
            this.m_EnrollNumber = EnrollNumber;
            this.m_Date = Date;
            this.m_Hour = Hour;
            this.m_StateInOut = StateInOut;
            this.m_MachineID = MachineID;
        }

        public string CreateKey()
        {
            return this.CreateKey("");
        }

        public string CreateKey(SqlTransaction myTransaction)
        {
            return SqlHelper.GenCode(myTransaction, "");
        }

        public string CreateKey(string key)
        {
            return SqlHelper.GenCode(key);
        }

        public string CreateKey(SqlTransaction myTransaction, string key)
        {
            return SqlHelper.GenCode(myTransaction, key);
        }

        public DataTable CreateNullDataTable()
        {
            DataTable table = new DataTable();
            DataColumn column = new DataColumn("ID");
            DataColumn column2 = new DataColumn("EnrollNumber");
            DataColumn column3 = new DataColumn("EmployeeCode");
            DataColumn column4 = new DataColumn("EmployeeName");
            DataColumn column5 = new DataColumn("Date", Type.GetType("System.DateTime"));
            DataColumn column6 = new DataColumn("Hour", Type.GetType("System.DateTime"));
            DataColumn column7 = new DataColumn("StateInOut");
            DataColumn column8 = new DataColumn("MachineID");
            table.Columns.Add(column);
            table.Columns.Add(column2);
            table.Columns.Add(column3);
            table.Columns.Add(column4);
            table.Columns.Add(column5);
            table.Columns.Add(column6);
            table.Columns.Add(column7);
            table.Columns.Add(column8);
            return table;
        }

        public static DataTable CreateNullEmployeesDataTable()
        {
            DataTable table = new DataTable();
            DataColumn column = new DataColumn("EnrollNumber");
            table.Columns.Add(column);
            table.Clear();
            return table;
        }

        public string Delete(Guid ID)
        {
            string[] myParams = new string[] { "@ID" };
            object[] myValues = new object[] { ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_TIMEKEEPER_MACHINE_Delete", myParams, myValues);
        }

        public string Delete(SqlConnection myConnection, string ID)
        {
            string[] myParams = new string[] { "@ID" };
            object[] myValues = new object[] { ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "HRM_TIMEKEEPER_MACHINE_Delete", myParams, myValues);
        }

        public string Delete(SqlTransaction myTransaction, string ID)
        {
            string[] myParams = new string[] { "@ID" };
            object[] myValues = new object[] { ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "HRM_TIMEKEEPER_MACHINE_Delete", myParams, myValues);
        }

        public string DeleteAll()
        {
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_TIMEKEEPER_MACHINE_DeleteAll");
        }

        public bool Exist()
        {
            return this.Exist(this.m_ID);
        }

        public bool Exist(SqlTransaction myTransaction)
        {
            return this.Exist(myTransaction, this.m_ID);
        }

        public bool Exist(Guid ID)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@ID" };
            object[] myValues = new object[] { ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("M_Machine_Get", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                helper.Close();
                reader = null;
            }
            return hasRows;
        }

        public bool Exist(SqlTransaction myTransaction, Guid ID)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@ID" };
            object[] myValues = new object[] { ID };
            SqlDataReader reader = new SqlHelper().ExecuteReader(myTransaction, "M_Machine_Get", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                reader = null;
            }
            return hasRows;
        }

        public string Get()
        {
            return this.Get(this.ID);
        }

        public string Get(SqlConnection myConnection)
        {
            return this.Get(myConnection, this.ID);
        }

        public string Get(SqlTransaction myTransaction)
        {
            return this.Get(myTransaction, this.ID);
        }

        public string Get(Guid ID)
        {
            string str = "";
            string[] myParams = new string[] { "@ID" };
            object[] myValues = new object[] { ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("M_Machine_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_ID = reader.GetGuid(reader.GetOrdinal("ID"));
                    this.m_EnrollNumber = Convert.ToString(reader["EnrollNumber"]);
                    this.m_Date = Convert.ToDateTime(reader["Date"]);
                    this.m_Hour = Convert.ToDateTime(reader["Hour"]);
                    this.m_StateInOut = Convert.ToInt32(reader["StateInOut"]);
                    this.m_MachineID = Convert.ToString(reader["MachineID"]);
                    str = "OK";
                }
                reader.Close();
                reader = null;
            }
            helper.Close();
            return str;
        }

        public string Get(SqlConnection myConnection, Guid ID)
        {
            string str = "";
            string[] myParams = new string[] { "@ID" };
            object[] myValues = new object[] { ID };
            SqlDataReader reader = new SqlHelper().ExecuteReader(myConnection, "M_Machine_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_ID = reader.GetGuid(reader.GetOrdinal("ID"));
                    this.m_EnrollNumber = Convert.ToString(reader["EnrollNumber"]);
                    this.m_Date = Convert.ToDateTime(reader["Date"]);
                    this.m_Hour = Convert.ToDateTime(reader["Hour"]);
                    this.m_StateInOut = Convert.ToInt32(reader["StateInOut"]);
                    this.m_MachineID = Convert.ToString(reader["MachineID"]);
                    str = "OK";
                }
                reader.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlTransaction myTransaction, Guid ID)
        {
            string str = "";
            string[] myParams = new string[] { "@ID" };
            object[] myValues = new object[] { ID };
            SqlDataReader reader = new SqlHelper().ExecuteReader(myTransaction, "M_Machine_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_ID = reader.GetGuid(reader.GetOrdinal("ID"));
                    this.m_EnrollNumber = Convert.ToString(reader["EnrollNumber"]);
                    this.m_Date = Convert.ToDateTime(reader["Date"]);
                    this.m_Hour = Convert.ToDateTime(reader["Hour"]);
                    this.m_StateInOut = Convert.ToInt32(reader["StateInOut"]);
                    this.m_MachineID = Convert.ToString(reader["MachineID"]);
                    str = "OK";
                }
                reader.Close();
                reader = null;
            }
            return str;
        }

        public DataTable GetList()
        {
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("HRM_TIMEKEEPER_MACHINE_GetList");
        }

        public string Insert()
        {
            return this.Insert(this.m_ID, this.m_EnrollNumber, this.m_Date, this.m_Hour, this.m_StateInOut, this.m_MachineID);
        }

        public string Insert(SqlConnection myConnection)
        {
            return this.Insert(myConnection, this.m_ID, this.m_EnrollNumber, this.m_Date, this.m_Hour, this.m_StateInOut, this.m_MachineID);
        }

        public string Insert(SqlTransaction myTransaction)
        {
            return this.Insert(myTransaction, this.m_ID, this.m_EnrollNumber, this.m_Date, this.m_Hour, this.m_StateInOut, this.m_MachineID);
        }

        public string Insert(Guid ID, string EnrollNumber, DateTime Date, DateTime Hour, int StateInOut, string MachineID)
        {
            string[] myParams = new string[] { "@ID", "@EnrollNumber", "@Date", "@Hour", "@StateInOut", "@MachineID" };
            object[] myValues = new object[] { ID, EnrollNumber, Date, Hour, StateInOut, MachineID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_TIMEKEEPER_MACHINE_Insert", myParams, myValues);
        }

        public string Insert(SqlConnection myConnection, Guid ID, string EnrollNumber, DateTime Date, DateTime Hour, int StateInOut, string MachineID)
        {
            string[] myParams = new string[] { "@ID", "@EnrollNumber", "@Date", "@Hour", "@StateInOut", "@MachineID" };
            object[] myValues = new object[] { ID, EnrollNumber, Date, Hour, StateInOut, MachineID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "HRM_TIMEKEEPER_MACHINE_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction, Guid ID, string EnrollNumber, DateTime Date, DateTime Hour, int StateInOut, string MachineID)
        {
            string[] myParams = new string[] { "@ID", "@EnrollNumber", "@Date", "@Hour", "@StateInOut", "@MachineID" };
            object[] myValues = new object[] { ID, EnrollNumber, Date, Hour, StateInOut, MachineID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "HRM_TIMEKEEPER_MACHINE_Insert", myParams, myValues);
        }

        public string NewID()
        {
            return this.NewID("");
        }

        public string NewID(string key)
        {
            return SqlHelper.GenCode("HRM_TIMEKEEPER_MACHINE", "HRM_TIMEKEEPER_MACHINEID", key);
        }

        public string SetShift(DateTime BeginDate, DateTime EndDate, string EmployeeCode)
        {
            string[] myParams = new string[] { "@BeginDate", "@EndDate", "@EmployeeCode" };
            object[] myValues = new object[] { BeginDate, EndDate, EmployeeCode };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_TIMEKEEPER_MACHINE_SetShift", myParams, myValues);
        }

        public string UpdateTimeKeeper(DateTime BeginDate, DateTime EndDate, string EmployeeCode)
        {
            string[] myParams = new string[] { "@BeginDate", "@EndDate", "@EmployeeCode" };
            object[] myValues = new object[] { BeginDate, EndDate, EmployeeCode };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_TIMEKEEPER_MACHINE_Update", myParams, myValues);
        }

        public string Copyright
        {
            get
            {
                return "C\x00f4ng Ty Phần Mềm Ho\x00e0n Hảo";
            }
        }

        public DateTime Date
        {
            get
            {
                return this.m_Date;
            }
            set
            {
                this.m_Date = value;
            }
        }

        public string EnrollNumber
        {
            get
            {
                return this.m_EnrollNumber;
            }
            set
            {
                this.m_EnrollNumber = value;
            }
        }

        public DateTime Hour
        {
            get
            {
                return this.m_Hour;
            }
            set
            {
                this.m_Hour = value;
            }
        }

        public Guid ID
        {
            get
            {
                return this.m_ID;
            }
            set
            {
                this.m_ID = value;
            }
        }

        public string MachineID
        {
            get
            {
                return this.m_MachineID;
            }
            set
            {
                this.m_MachineID = value;
            }
        }

        public string Product
        {
            get
            {
                return "Class HRM_TIMEKEEPER_MACHINE";
            }
        }

        public int StateInOut
        {
            get
            {
                return this.m_StateInOut;
            }
            set
            {
                this.m_StateInOut = value;
            }
        }

        public string Version
        {
            get
            {
                return "1.0.0.0";
            }
        }
    }
}

